import {
  ILexerCondition
} from '../types';

export const EOF = 1;
export const ERROR = 2;

export const LEXER_RULES = [
  /^\s+/,
  /^(-?([0-9]|[1-9][0-9]+))(\.[0-9]+)?([eE][-+]?[0-9]+)?\b/,
  /^"(?:\\[\\"bfnrt\/]|\\u[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*"/, // eslint-disable-line
  /^{/,
  /^}/,
  /^\[/,
  /^]/,
  /^,/,
  /^:/,
  /^true\b/,
  /^false\b/,
  /^null\b/,
  /^$/,
  /^./
];

export const LEXER_CONDITIONS: Record<string, ILexerCondition> = {
  INITIAL: {
    rules: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
    inclusive: true
  }
};

export const PARSER_SYMBOLS: Record<string, number> = {
  error: 2,
  STRING: 4,
  EOF: 14,
  NUMBER: 6,
  NULL: 8,
  TRUE: 10,
  FALSE: 11,
  JSONString: 3,
  JSONNumber: 5,
  JSONNullLiteral: 7,
  JSONBooleanLiteral: 9,
  JSONText: 12,
  JSONValue: 13,
  JSONObject: 15,
  JSONArray: 16,
  JSONMemberList: 19,
  JSONMember: 20,
  JSONElementList: 25,
  '{': 17,
  '}': 18,
  ':': 21,
  ',': 22,
  '[': 23,
  ']': 24,
  $accept: 0,
  $end: 1
};

export const PARSER_TERMINALS: Record<number, string> = {
  2: 'error',
  4: 'STRING',
  6: 'NUMBER',
  8: 'NULL',
  10: 'TRUE',
  11: 'FALSE',
  14: 'EOF',
  17: '{',
  18: '}',
  21: ':',
  22: ',',
  23: '[',
  24: ']'
};

export const PARSER_PRODUCTIONS = [
  0,
  [3, 1],
  [5, 1],
  [7, 1],
  [9, 1],
  [9, 1],
  [12, 2],
  [13, 1],
  [13, 1],
  [13, 1],
  [13, 1],
  [13, 1],
  [13, 1],
  [15, 2],
  [15, 3],
  [20, 3],
  [19, 1],
  [19, 3],
  [16, 2],
  [16, 3],
  [25, 1],
  [25, 3]
];

export const PARSER_TABLE: Record<number, number | [number] | [number, number]>[] = [{
  3: 5,
  4: [1, 12],
  5: 6,
  6: [1, 13],
  7: 3,
  8: [1, 9],
  9: 4,
  10: [1, 10],
  11: [1, 11],
  12: 1,
  13: 2,
  15: 7,
  16: 8,
  17: [1, 14],
  23: [1, 15]
}, {
  1: [3]
}, {
  14: [1, 16]
}, {
  14: [2, 7],
  18: [2, 7],
  22: [2, 7],
  24: [2, 7]
}, {
  14: [2, 8],
  18: [2, 8],
  22: [2, 8],
  24: [2, 8]
}, {
  14: [2, 9],
  18: [2, 9],
  22: [2, 9],
  24: [2, 9]
}, {
  14: [2, 10],
  18: [2, 10],
  22: [2, 10],
  24: [2, 10]
}, {
  14: [2, 11],
  18: [2, 11],
  22: [2, 11],
  24: [2, 11]
}, {
  14: [2, 12],
  18: [2, 12],
  22: [2, 12],
  24: [2, 12]
}, {
  14: [2, 3],
  18: [2, 3],
  22: [2, 3],
  24: [2, 3]
}, {
  14: [2, 4],
  18: [2, 4],
  22: [2, 4],
  24: [2, 4]
}, {
  14: [2, 5],
  18: [2, 5],
  22: [2, 5],
  24: [2, 5]
}, {
  14: [2, 1],
  18: [2, 1],
  21: [2, 1],
  22: [2, 1],
  24: [2, 1]
}, {
  14: [2, 2],
  18: [2, 2],
  22: [2, 2],
  24: [2, 2]
}, {
  3: 20,
  4: [1, 12],
  18: [1, 17],
  19: 18,
  20: 19
}, {
  3: 5,
  4: [1, 12],
  5: 6,
  6: [1, 13],
  7: 3,
  8: [1, 9],
  9: 4,
  10: [1, 10],
  11: [1, 11],
  13: 23,
  15: 7,
  16: 8,
  17: [1, 14],
  23: [1, 15],
  24: [1, 21],
  25: 22
}, {
  1: [2, 6]
}, {
  14: [2, 13],
  18: [2, 13],
  22: [2, 13],
  24: [2, 13]
}, {
  18: [1, 24],
  22: [1, 25]
}, {
  18: [2, 16],
  22: [2, 16]
}, {
  21: [1, 26]
}, {
  14: [2, 18],
  18: [2, 18],
  22: [2, 18],
  24: [2, 18]
}, {
  22: [1, 28],
  24: [1, 27]
}, {
  22: [2, 20],
  24: [2, 20]
}, {
  14: [2, 14],
  18: [2, 14],
  22: [2, 14],
  24: [2, 14]
}, {
  3: 20,
  4: [1, 12],
  20: 29
}, {
  3: 5,
  4: [1, 12],
  5: 6,
  6: [1, 13],
  7: 3,
  8: [1, 9],
  9: 4,
  10: [1, 10],
  11: [1, 11],
  13: 30,
  15: 7,
  16: 8,
  17: [1, 14],
  23: [1, 15]
}, {
  14: [2, 19],
  18: [2, 19],
  22: [2, 19],
  24: [2, 19]
}, {
  3: 5,
  4: [1, 12],
  5: 6,
  6: [1, 13],
  7: 3,
  8: [1, 9],
  9: 4,
  10: [1, 10],
  11: [1, 11],
  13: 31,
  15: 7,
  16: 8,
  17: [1, 14],
  23: [1, 15]
}, {
  18: [2, 17],
  22: [2, 17]
}, {
  18: [2, 15],
  22: [2, 15]
}, {
  22: [2, 21],
  24: [2, 21]
}];

export const PARSER_DEFAULT_ACTIONS: Record<number, [number, number]> = {
  16: [2, 6]
};
